﻿using Kevin.Shop.Business.Service.Entity.Helper;
using RiderShop.Mobile.Common.Attributes;
using RiderShop.Mobile.Common.Component;
using RiderShop.Mobile.Modle.MyAccount;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace RiderShop.Mobile.Controllers.MyAccount
{
    public partial class MyAccountController : ThemeController
    {
        [Authorize]
        [PhoneVerifiedAttribute]
        public ActionResult PaymentCard()
        {
            var user = WebClientContext.Current.GetCurrentUser();

            BalanceModel model = new BalanceModel();
            var list = model.GetUserPaymentCardList(WebClientContext.Current.UserId);

            return View(WebClientContext.Current.SiteTheme, "MyAccount", "PaymentCard", WebClientContext.Current.CacheKeyDefaultMasterPage, list);

        }


        [Authorize]
        [PhoneVerifiedAttribute]
        public ActionResult BalanceAccount()
        {
            var user = WebClientContext.Current.GetCurrentUser();

            BalanceModel model = new BalanceModel();
            model.GetUserBalanceAccount(WebClientContext.Current.UserId);

            return View(WebClientContext.Current.SiteTheme, "MyAccount", "BalanceAccount", WebClientContext.Current.CacheKeyDefaultMasterPage, model);

        }

        [Authorize]
        [PhoneVerifiedAttribute]
        public ActionResult BalanceIncomeHistory()
        {
            var user = WebClientContext.Current.GetCurrentUser();

            BalanceModel model = new BalanceModel();
            model.GetUserBalanceAccount(WebClientContext.Current.UserId);

            return View(WebClientContext.Current.SiteTheme, "MyAccount", "BalanceIncomeHistory", WebClientContext.Current.CacheKeyDefaultMasterPage, model);

        }

        [Authorize]
        [PhoneVerifiedAttribute]
        public ActionResult AddPaymentCard(string card, string password)
        {
            var user = WebClientContext.Current.GetCurrentUser();

            BalanceModel model = new BalanceModel();
            if (!string.IsNullOrWhiteSpace(card) && !string.IsNullOrWhiteSpace(password))
            {
                var response = model.UpdateUserPaymentCard(card, password, WebClientContext.Current.UserId);
                if (response.Status)
                {
                    return RedirectToAction("PaymentCard");
                }
                else
                {
                    model.ErrorMessage = response.ErrorMessage;
                }
            }

            return View(WebClientContext.Current.SiteTheme, "MyAccount", "AddPaymentCard", WebClientContext.Current.CacheKeyDefaultMasterPage, model);

        }

    }
}
